package com.xique.common.datascope.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collection;

/**
 * 关联查询切面
 *
 * @author xl.liu
 * @date 2019-12-18
 */
@Component
@Aspect
public class SetFieldValueAspect {

    @Autowired
    private SetFieldValueUtil beanUtil;

    @Around("@annotation(com.xique.common.datascope.annotation.NeedSetFieldValue)")
    public Object doSetFieldValue(ProceedingJoinPoint pjp) throws Throwable {
        Object res = pjp.proceed();
        if (res instanceof Collection) {
        	Collection col = (Collection) res;
        	if(!col.isEmpty()) {
        		this.beanUtil.setValue(col);
        	}
        }else {
        	//add by xl.liu 后面需要修改
            if(null != res){
                this.beanUtil.setValue(res);
            }
        }
        return res;
    }
}

